package com.wuzhun.wxmp;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.generator.FastAutoGenerator;
import com.baomidou.mybatisplus.generator.config.OutputFile;
import com.baomidou.mybatisplus.generator.config.rules.NamingStrategy;
import com.baomidou.mybatisplus.generator.engine.FreemarkerTemplateEngine;
import com.wuzhun.wxmp.model.entity.BaseEntity;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;

import java.util.Collections;

@SpringBootTest
public class MybatisPlusGenerator {

    @Test
    public void generator(){

        FastAutoGenerator.create("jdbc:mysql://110.42.230.126:3306/weixin?useUnicode=true&characterEncoding=utf8", "weixin", "K622szJ8Jnw84cYJ")
                .globalConfig(builder -> {
                    builder.author("Paulin") // 设置作者
                            .enableSwagger() // 开启 swagger 模式
                            .fileOverride() // 覆盖已生成文件
                            .outputDir("E:\\Projects\\Java\\download_cms\\src\\main\\java"); // 指定输出目录
                })
                .packageConfig(builder -> {
                    builder.parent("com.liuzou.wxmp") // 设置父包名
                            .moduleName(null) // 设置父包模块名
                            .entity("model.entity")
                            .service("service")
                            .serviceImpl("service.impl")
                            .mapper("mapper")
                            .controller("controller")
                            .pathInfo(Collections.singletonMap(OutputFile.mapperXml, "E:\\Projects\\Java\\download_cms\\src\\main\\resources\\spring\\mapper")); // 设置mapperXml生成路径
                })
                .strategyConfig(builder -> {
                    builder.entityBuilder()
                            .superClass(BaseEntity.class)
                            .enableChainModel()
                            .disableSerialVersionUID()
                            .enableLombok()
                            .enableRemoveIsPrefix()
                            .enableTableFieldAnnotation()
//                            .logicDeleteColumnName("delete_flag")
//                            .logicDeletePropertyName("deleteFlag")
                            .naming(NamingStrategy.underline_to_camel)
                            .columnNaming(NamingStrategy.underline_to_camel)
                            //.addSuperEntityColumns("id", "county_in_to", "county_out_to", "to_county_in", "to_county_out", "appoint","distribute", "retire", "recruit_number", "recruit_proportion", "empty_number", "status", "type",  "created_time", "updated_time")
                            .idType(IdType.AUTO)
                            .build();
                    builder.addInclude("pre_setting") // 设置需要生成的表名
                            .addTablePrefix("pre_");// 设置过滤表前缀
                })
                .templateEngine(new FreemarkerTemplateEngine()) // 使用Freemarker引擎模板，默认的是Velocity引擎模板
                .execute();
    }

}